package week01;
 
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
 

class ProductPool {
 
    private BlockingQueue producstPool = new LinkedBlockingQueue();
 
    public ProductPool(BlockingQueue producstPool) {
        this.producstPool = producstPool;
    }
 
    /**
     * ���ɲ�Ʒ
     */
    public void product(Integer product) throws InterruptedException {
        producstPool.put( product);
        System.out.println(Thread.currentThread().getName()+"������"+product+"�Ų�Ʒ");
    }
 
    /**
     * ���Ѳ�Ʒ
     * @throws InterruptedException
     */
    public void consumr() throws InterruptedException {
        Integer take = (Integer) producstPool.take();
        System.out.println(Thread.currentThread().getName()+"������"+take+"�Ų�Ʒ");      
    }
}
 
 
/**
 * @author 79282
 */
public class LinkBlockKingQueue extends Thread{
 
 
    public static void main(String[] args) {
    	
        ProductPool productPool = new ProductPool(new LinkedBlockingQueue());
        LinkBlockKingQueue link = new LinkBlockKingQueue();
        
        try {
        	synchronized(link) {
        		System.out.println("���߳̽�������״̬");
        		link.sleep(5000);	
        	}
        	
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
        
        new Thread(()->{
            for (int i = 1; i <= 50; i++) {
                try {
                    productPool.product(i);                  
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
 
            }
        },"�������߳�").start();
 
 
        new Thread(()->{
            for (int i = 1; i <= 50; i++) {
                try {
                    productPool.consumr();
                   
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
 
            }
        },"�������߳�").start();
    }
 
}